Skip to content

feat(weather): add precipitation probability to the payload - #385

Open
adamecker wants to merge 1 commit into
jherforth:mainfrom
adamecker:feature/weather-precipitation-probability
Open

adamecker wants to merge 1 commit into
jherforth:mainfrom
adamecker:feature/weather-precipitation-probability

Conversation

@adamecker

Copy link
Copy Markdown
Contributor

What this does

OpenWeatherMap's /forecast items already carry pop (probability of precipitation, 0–1), but the canonical weather payload ignored it. This change surfaces it as precipitationProbability, an integer percent (0–100):

  • forecast[] — each day takes the maximum pop across its 3-hour blocks (the day's likeliest block).
  • hourly[] — each 3-hour point carries its own pop, converted to a percent.
  • payload.js — the canonical payload now carries the field on both arrays, and validatePayload rejects values outside 0–100 (a value like 140 is a provider bug, not a display value).
  • Providers that don't supply a probability (Home Assistant, demo) carry null for the field, which stays valid. The widget hides the value when it is absent, so this is safe to land independently of the widget change that renders it.

Payload example

From the payload-contract test in server/tests/weatherProviders.test.js, which builds a payload with a 60% daily probability and a 20% hourly probability and asserts validatePayload passes:

{
  "forecast": [
    {
      "date": "2026-07-08",
      "high": 70,
      "low": 60,
      "condition": "rainy",
      "precipitation": 2,
      "precipitationProbability": 60
    }
  ],
  "hourly": [
    {
      "timestamp": 1783536000,
      "temp": 65,
      "precipitation": 0,
      "precipitationProbability": 20
    }
  ]
}

The OpenWeatherMap fixture test covers the conversion itself: a pop of 0.6 on the likeliest 3-hour block becomes 60 on both that hourly point and its day, while the second day peaks at a pop of 0.25 and becomes 25. When OpenWeatherMap sends no pop, the field is null on both arrays.

Tests

Verified locally on the rebased branch:

  • Server: full suite — 772 tests, 772 pass, 0 fail (cd server && npm test).
  • Server weather providers file: 16/16 pass, including 3 new probability tests (summarizeForecast conversion, missing pop stays null, payload contract + validation).
  • Client: 98 test files, 1064 tests, all pass (cd client && npm test).
  • Vite build: passes (cd client && npm run build, built in 6.40s).

Generated with Muse AI 🤖

OWM /forecast items carry pop (0-1); surface it as precipitationProbability
(0-100) on forecast[] (daily max) and hourly[], via payload.js and
summarizeForecast. Home Assistant has no equivalent and the demo snapshot
has none, so both stay null and the client hides the field when absent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant